<?php

class Speed extends CActiveRecord
{
	/**
	 * The followings are the available columns in table '{{speed}}':
	 * @var integer $id
	 * @var string $name
	 * @var integer $world_in
	 * @var integer $world_out
	 * @var integer $ukraine_in
	 * @var integer $ukraine_out
	 * @var boolean $is_active
	 * @var string $create_time
	 * @var string $update_time
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{speed}}';
	}

	public function scopes()
	{
		return array(
			'active'=>array(
				'condition'=>'t.is_active=1',
				'order'=>'t.id',
			),
				//'withspeed'=>array(
				//'with'=>'speed',
			//),
		);
	}
	
	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, world_in, world_out, ukraine_in, ukraine_out', 'required'),
			array('world_in, world_out, ukraine_in, ukraine_out', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>128),
			array('is_active', 'boolean'),
			array('create_time, update_time', 'unsafe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, world_in, world_out, ukraine_in, ukraine_out, is_active, create_time, update_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => Yii::t('main','Id'),
			'name' => Yii::t('main','Name'),
			'world_in' => Yii::t('main','World In'),
			'world_out' => Yii::t('main','World Out'),
			'ukraine_in' => Yii::t('main','Ukraine In'),
			'ukraine_out' => Yii::t('main','Ukraine Out'),
			'is_active' => Yii::t('main','Is Active'),
			'create_time' => Yii::t('main','Create Time'),
			'update_time' => Yii::t('main','Update Time'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);

		$criteria->compare('name',$this->name,true);

		$criteria->compare('world_in',$this->world_in);

		$criteria->compare('world_out',$this->world_out);

		$criteria->compare('ukraine_in',$this->ukraine_in);

		$criteria->compare('ukraine_out',$this->ukraine_out);

		$criteria->compare('is_active',$this->is_active);

		$criteria->compare('create_time',$this->create_time,true);

		$criteria->compare('update_time',$this->update_time,true);

		return new CActiveDataProvider('Speed', array(
			'criteria'=>$criteria,
			'pagination'=>array('pageSize'=>Setting::get('PerPage')),
		));
	}
	
	public function behaviors()
    {
        return array(
			'History' => array(
                'class'=>'application.components.behaviors.HistoryBehavior',
            ),
			'OldAttributes' => array(
				'class'=>'application.components.behaviors.OldAttributesBehavior',
			),
            'NotActiveOnDelete' => array(
            	'class'=>'application.components.behaviors.NotActiveOnDeleteBehavior',
            ),
        );
    }
}